package cn.xinyangtong.manager.controller;

import cn.xinyangtong.common.pojo.DefaultResult;
import cn.xinyangtong.manager.entity.Status;
import cn.xinyangtong.manager.entity.TreeNode;
import cn.xinyangtong.manager.service.ContentCategoryService;
import cn.xinyangtong.pojo.TbContentCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 内容分类管理
 * Created by fengbo on 2017/6/17.
 */
@Controller
@RequestMapping("/content/category")
public class ContentCategoryController {

    @Autowired
    private ContentCategoryService contentCategoryService;

    /****
     * 内容分类树形节点
     * @param parentId
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public List<TreeNode> getContentCatList(@RequestParam(value = "id", defaultValue = "0")Long parentId) {
        return contentCategoryService.getCategoryList(parentId);
    }

    /***
     * 创建一个内容分类节点
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping("/create")
    @ResponseBody
    public DefaultResult createContentCategory(Long parentId, String name) {
        return contentCategoryService.insertContentCategory(parentId, name);
    }

    /****
     * 内容分类管理修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public DefaultResult updateContentCategory(TbContentCategory contentCategory) {
        return contentCategoryService.updateContentCategoryById(contentCategory);
    }

    /****
     * 删除内容分类
     */
    @RequestMapping("/delete")
    @ResponseBody
    public DefaultResult deleteContentCategory(Long id) {
        return contentCategoryService.deleteContentCategory(id);
    }
}
